package com.kdgc.power.common.util;

import java.io.UnsupportedEncodingException;
import java.util.Random;

public class RandUtil {
    private static final Random random = new Random();

    /**
     * @return  X   0 <= X < up
     */
    public static int getInt(int up) {
        return random.nextInt(up);
    }

    /**
     * @return X  down <= X <= up
     */
    public static int getInt(int down, int up) {
        return random.nextInt(up - down + 1) + down;
    }

    /**
     * @return  count 个常用汉字（从 3755 个GBK一级常用汉字里随机生成）
     */

    public static String getCommonChinese(int count) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < count; i++) {
            int rand = RandUtil.getInt(3755);
            try {
                sb.append(new String(new byte[]{(byte) (rand / 94 - 80), (byte) (rand % 94 - 95)}, "GBK"));
            } catch (UnsupportedEncodingException ignored) {
            }
        }
        return sb.toString();
    }

    /**
     * @return count 个 大写字母（A-Z）
     */

    public static String getUppercase(int count) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < count; i++)
            sb.append((char) getInt(65, 90));
        return sb.toString();
    }
    /**
     * @return count 个 小写字母（a-z）
     */

    public static String getLowercase(int count) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < count; i++)
            sb.append((char) getInt(97, 122));
        return sb.toString();
    }


}
